/*
 * @(#)OrderController.java 2013-4-11 下午04:33:01
 *
 * Copyright 2013 Beijing Axesline Technology Co..Ltd All rights reserved.
 * 该程序的所有权为北京铭扬谷地咨询有限公司 .
 * 使用之前必须得到北京铭扬谷地咨询有限公司的许可;
 */
package com.minyond.demo.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.minyond.demo.entity.Order;
import com.minyond.demo.entity.User;
import com.minyond.demo.service.OrderService;
import com.minyond.demo.service.UserService;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2013</p>
 * <p>Company: minyond</p>
 * <P>Created Date :2013-4-11</P> 
 * @author zhangfeng
 * @version 1.0
 */
@Controller
@RequestMapping("/demo")
public class OrderController {
    
    private OrderService orderService;
    
    private UserService userService;
    
    @RequestMapping(value = "/findOrder")
    public String findOrder(Model model){
        List<Order> orderList = this.orderService.getAllOrder();
        
        model.addAttribute("orderList",orderList);
        
        return "demo/find_order";
    }
        
    @RequestMapping(value = "/addOrder")
    public String addOrder(Model model){
        List<User> userList = this.userService.getAllUser();
        
        model.addAttribute("userList",userList);
        return "demo/add_order";
    }
    
    @RequestMapping(value = "/saveOrder",method = RequestMethod.POST)
    public String saveOrder(@Valid @ModelAttribute("order") Order order){
        this.orderService.saveOrder(order);
        
        return "redirect:findOrder";
    }
    
    @Autowired
    public void setOrderService(OrderService orderService) {
        this.orderService = orderService;
    }
    
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
